/**
Read a set of integers into a vector. Calculate and print the sum of each pair 
of adjacent elements in the vector. If there is an odd number, tell the user 
and print the value of the last element without summing it. Now change your 
program so that it prints the sum of the first and last elements, followed by 
the sum of the second and second-to-last and so on.
**/
#include <iostream>
#include <vector>

using namespace std;

int SumOfTwo(){
	vector<int> input;
	int in,sum=0;
	while(cin>>in){
		input.push_back(in);
	}
	for(vector<int>::size_type i=0; i!=input.size(); i++){
		if(i%2){
			sum+=input[i];
			cout<<"The sum is: "<<sum<<endl;
		}
		else{
			sum=input[i];
			if(i==input.size()-1)
				cout<<"only one element left: "<<input[i]<<endl;
		}
	}
	return 0;
}

int SumOfTwo2(){
	vector<int> numbers;
	int input;
	cout<<"input several numbers(Ctrl+z to end):"<<endl;
	while(cin>>input)
		numbers.push_back(input);

	if(numbers.size()==0){
		cout<<"input is empty"<<endl;
		return -1;
	}

	cout<<"sum of adjacent numbers:"<<endl;
	for(vector<int>::size_type i=0; i<numbers.size()-1; i+=2){
		cout<<numbers[i]+numbers[i+1]<<" ";
		if((i+1)%6==0)
			cout<<endl;
	}
	cout<<endl;

	if(numbers.size()%2)
		cout<<"one single number left:"<<numbers[numbers.size()-1]<<endl;

	return 0;
}

void PrintMiddle(vector<int> numbers){
	cout<<"The middle element is: "
		<<*(numbers.begin() + numbers.size()/2)<<endl;
}

/**
Write a program to create a vector with 10 elements. Using an iterator, assign 
each element a value that is twice its current value.

**/
int TwiceVector(){
	vector<int> numbers;
	for(int i=0; i<10; i++){
		numbers.push_back(i);
	}

	for(vector<int>::iterator iter = numbers.begin(); 
		iter != numbers.end(); iter++){
			*iter = *iter * 2;
			cout<<*iter<<" ";
	}
	cout<<endl;

	PrintMiddle(numbers);
	return 0;
}